import json
import requests

url = "https://api.siliconflow.cn/v1/embeddings"

payload = {
    "input": "今天天气很好",
    "encoding_format": "float",
    "model": "BAAI/bge-large-zh-v1.5"
}
headers = {
    "Authorization": "Bearer sk-pusgnznrckhdogxrchddbfzrypvljzjdydjogvnfbprehtkj",
    "Content-Type": "application/json"
}

# 发送 POST 请求
response = requests.request("POST", url, json=payload, headers=headers)

json_data = response.json()
json_data['text'] = payload['input']


# 保存到文件 utf-8编码
with open('bge_emb.json', 'w', encoding='utf-8') as f:
    json.dump(json_data, f, ensure_ascii=False, indent=4)

emb = json_data['data'][0]['embedding']
print(f"emb 的长度为: {len(emb)}")
print(f"emb 的类型为: {type(emb)}")
print(f"emb 的前5 个值为: {emb[:5]}")

    
